<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/website/common/base.jsp"%>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>${webname }-忘记密码</title>
    <%@ include file="/website/common/common.jsp"%>
    <link href="${webctx }/css/login.css" rel="stylesheet" type="text/css" />
</head>
<style>
    .ft-hd-nav{
        padding-top: 20px;
    }
</style>
<body rmenu="none">
<div id="head-min" class="head-min">
    <a class="logo" href="${ctx }/website/index.jsp"><img style="top:0;" src="${webctx }/images/logo.png"/></a>
    <p class="log-in">找回密码</p>
    <p class="service-phone">客服电话：400-805-5522</p>
</div>

<div id="wrap-main">
    <div class="wid990 forget findpwdcon">
        <div class="steps t-1"></div>
        <div class="forget-main">
            <ul class="items">
                <li class="item">
                    <div class="item-title">账号：</div>
                    <div class="itemInp-ct">
                        <div class="ipt norWidthIpt"><input name="loginname" type="text" class="inp" placeholder="请输入用户名/手机号" style="height:36px;line-height:36px;"></div>
                    </div>
                    <div class="itemTip" id="logintip"></div>
                </li>
                <li class="item">
                    <div class="item-title">验证码：</div>
                    <div class="itemInp-ct">
                        <div class="ipt" style="width:205px;"><input type="text" name="checkcode" class="inp" placeholder="输入验证码" style="height:36px;line-height:36px;"></div>
                        <span  class="yzm-img" style="z-index: 99">
                       		<img id="checkcodeimg" onclick="getcheckcodeimg()" src="" width="110" height="38" alt="">
                          	<span class="yzm-tips">看不清？<a href="javascript:getcheckcodeimg()">换一张</a></span>
                      	</span>
                    </div>
                    <div class="itemTip" id="codetip"></div>
                    <div class="aui-clearfix"></div>
                </li>
                <li class="item">
                    <div class="line8"></div><div class="line8"></div><div class="line8"></div><div class="line8"></div>
                    <div class="itemInp-ct pt-20"><a href="javascript:next1();" class="reg-btn">下一步</a></div>
                </li>
            </ul>
        </div>
    </div>
    <div class="wid990 forget findpwdcon hide">
        <div class="steps t-2"></div>
        <div class="forget-main">
            <ul class="items">
                <li class="item">
                    <div class="itemInp-ct padd-l0">短信已发送到<strong class="phTxt" id="usephone"></strong> 请输入短信验证码</div>
                </li>
                <li class="item">
                    <div class="item-title">验证码：</div>
                    <div class="itemInp-ct">
                        <div class="ipt"><input type="text" name="smscode" class="inp" placeholder="输入验证码" style="width:200px;height:36px;line-height:36px;"></div>
                        <a href="javascript:tosendsms();" id="smsbtn" class="yzm-btn">重新发送</a>
                    </div>
                    <div class="itemTip" id="itemTip_old"></div>
                </li>
                <li class="item">
                    <div class="itemInp-ct pt-20"><a href="javascript:next2();" class="reg-btn">下一步</a></div>
                </li>
            </ul>
        </div>
    </div>
    <div class="wid990 forget findpwdcon hide">
        <div class="steps t-3"></div>
        <div class="forget-main">
            <ul class="items">
                <li class="item">
                    <div class="item-title">新密码：</div>
                    <div class="itemInp-ct">
                        <div class="ipt norWidthIpt"><input name="newpwd" type="password" class="inp" placeholder="请输入新密码" style="height:36px;line-height:36px;"></div>
                    </div>
                    <div class="itemTip"></div>
                </li>
                <li class="item">
                    <div class="item-title">重复新密码：</div>
                    <div class="itemInp-ct">
                        <div class="ipt norWidthIpt"><input name="newpwd2" type="password" class="inp" placeholder="请重复新的密码" style="height:36px;line-height:36px;"></div>
                    </div>
                    <div class="itemTip"></div>
                </li>
                <li style="padding:0px">
                    <div class="item-title"></div>
                    <div class="itemInp-ct" style="padding-bottom:8px">
                        <div style="color:#FF6767;text-align:center;" id="tipold"></div>
                    </div>
                </li>
                <li class="item">
                    <div class="itemInp-ct"><a href="javascript:ok();" class="reg-btn">确定</a></div>
                </li>
            </ul>
        </div>
    </div>
    <div class="wid990 forget findpwdcon hide">
        <div class="steps t-4"></div>
        <div class="forget-main">
            <ul class="items">
                <li class="item">
                    <div class="itemInp-ct">
                        <div class="editTxt">
                            <img src="${webctx }/images/ok_y.png" />
                            <p class="pt-20">恭喜，密码已修改成功</p>
                        </div>
                    </div>
                </li>
                <li class="item">
                    <div class="itemInp-ct pt-20"><a href="${ctx }/user/showlogin" class="reg-btn">去登录</a></div>
                </li>
            </ul>
        </div>
    </div>
</div>

<%@ include file="/website/common/foot-site.jsp"%>
<script type="text/javascript" src="${webctx}/js/sms.js"></script>
</body>
</html>
<script>
    $(function(){
        getcheckcodeimg();
    })
    function getcheckcodeimg(){
        $("#checkcodeimg").attr("src",server+"/validateimg?d="+new Date().getTime());
    }
    var user;
    function checkloginname(fun){
        $(".itemTip").text('');
        if ($("[name='loginname']").val() == null || $("[name='loginname']").val() == "") {
            $("#logintip").text("账号不能为空！");
            return false;
        }

        $w.httpRequest({
            url:apiroot+"/user/checkloginname",
            data:{"loginname":$("[name='loginname']").val()},
            ok:function(ret){
                user=ret.Data;
                fun();
            },fail:function(ret){
                if(ret.MsgCode=='2')$("#logintip").text("账号不存在");
//                else if(ret.MsgCode=='3')$("#logintip").text("该手机绑定用户名，请输入用户名！");
                else if(ret.MsgCode=='4')$("#logintip").text("该账号暂未绑定手机，可以向客服求助哦！");
                else $("#logintip").text(ret.MsgDesc);
                return false;
            }
        })
    }
    function next1(){
        checkloginname(function(){
            $w.httpRequest({
                url:apiroot+"/user/checkimgcode",
                data:{"code":$("[name='checkcode']").val()},
                ok:function(ret){
                    if(ret.Data){
                        tosendsms();
                        $("#usephone").text(user.phone);
                        $(".findpwdcon").hide();
                        $(".findpwdcon").eq(1).show();
                    }else $("#codetip").text("验证码错误或已失效，请重新输入");
                }
            })

        })
    }
    function tosendsms(){
        sendsms(user.phone,'findpwd','smsbtn');
    }
    function next2(){
        $w.httpRequest({
            url:apiroot+"/user/checksmscode",
            data:{"mobile":user.phone,"smscode":$("[name='smscode']").val()},
            ok:function(ret){
                if(ret.Data=='true'){
                    $(".findpwdcon").hide();
                    $(".findpwdcon").eq(2).show();
                }else $("#itemTip_old").text('验证码错误或已失效，请重新输入');
            }
        })
    }
    var submiting=false;
    function ok(){
        $(".itemTip").text('');
        if($("[name='newpwd']").val().length<6 || $("[name='newpwd']").val().length >16){
            $("[name='newpwd']").parent().parent().next().text("请输入6至16位的密码");
            return;
        }
        if($("[name='newpwd2']").val()==''){
            $("[name='newpwd2']").parent().parent().next().text("请再一次输入新密码");
            return;
        }
        if($("[name='newpwd']").val()!=$("[name='newpwd2']").val()){
            $("[name='newpwd2']").parent().parent().next().text("两次输入密码不一致，请重新输入");
            return ;
        }
        if(!submiting){
            submiting=true;
            $w.httpRequest({
                url:apiroot+"/user/findpwd",
                data:{"userid":user.id,"phone":user.phone,"smscode":$("[name='smscode']").val(),"newpwd":$("[name='newpwd']").val()},
                ok:function(ret){
                    $(".findpwdcon").hide();
                    $(".findpwdcon").eq(3).show();
                    try{
                        sessionStorage.setItem("_curUrl_",ctx+"/user/home");
                    }catch(e){}
                },fail:function(ret){
                    $("#tipold").text(ret.MsgDesc);
                    return false;
                },all:function(){submiting=false}
            })
        }
    }
</script>